<?php

namespace App\Http\Controllers;

use App\Models\WxClient;
use App\Services\HelpService;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Request;

use App\Http\Requests;

class CompanyWxClientController extends Controller
{
    public function index($company_id) {
        $data = HelpService::get_filter();
        $filter = [];
        $filter['project_id']['$in'] = [[], null, ''];
        $filter['company_id'] = $company_id;
        if (isset($data['project_id']) && $data['project_id']) {
            $filter['project_id']['$in'] = [$data['project_id']];
            $filter['contacts']['$in'] = [[], null, ''];
        }
        if (request()->input('page') === "0") {
            $wx_client = WxClient::where($filter)->select(['_id','nickName'])->get();
            return [
                'total' => $wx_client->count(),
                'data' => $wx_client,
            ];
        } else {
            $wx_client = WxClient::where($filter)->select(['_id','nickName'])->paginate(20);
            return $wx_client;
        }
    }
}
